//
//  XJWelcomeController.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/21.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJWelcomeController.h"
#import "XJUserAccountViewModel.h"


@interface XJWelcomeController ()

@property (nonatomic,weak) UIImageView *iconImage;
@property (nonatomic,weak) UILabel *welcomeLabel;

@end

@implementation XJWelcomeController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}

-(void)viewDidAppear:(BOOL)animated{

    [self.iconImage updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(100);
    }];
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:0 options:0 animations:^{
        
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.welcomeLabel.alpha = 1;
            
        }completion:^(BOOL finished) {
            
            //切换到首页控制器
            [[NSNotificationCenter defaultCenter]postNotificationName:@"changeRootVCNotification" object:self];
        }];
    }];

}

-(void)setupUI{

    UIImageView *iconImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    self.iconImage = iconImage;
    iconImage.layer.cornerRadius = 40;
    iconImage.layer.masksToBounds = YES;
    
    XJUserAccountViewModel *viewModel = [XJUserAccountViewModel sharedViewModel];
    [iconImage sd_setImageWithURL:[NSURL URLWithString:viewModel.accout.avatar_large]];
                                    
    UILabel *welcomeLabel = [[UILabel alloc]init];
    self.welcomeLabel = welcomeLabel;
    welcomeLabel.text = @"欢迎回来";
    welcomeLabel.alpha = 0;
    welcomeLabel.textColor = [UIColor darkGrayColor];
    welcomeLabel.font = [UIFont systemFontOfSize:16];
    
    [self.view addSubview:iconImage];
    [self.view addSubview:welcomeLabel];
    
    [iconImage makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(200);
        make.width.height.equalTo(80);
    }];
    
    [welcomeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(iconImage);
        make.top.equalTo(iconImage.bottom).offset(20);
    }];
    
}

@end
